﻿using System;
using System.Globalization;
using Succell.Dnn.JQuery;
using Succell.Dnn.JQuery.UI;
using DotNetNuke.Entities.Modules;

namespace Succell.Dnn.Modules.JQuery
{
    public partial class JQuery : PortalModuleBase
    {
        // use this for debug version of jquery.
        //public override System.Web.UI.Page Page
        //{
        //    get
        //    {
        //        if (null != base.Page)
        //        {
        //            base.Page.ClientScript.RegisterClientScriptInclude(typeof(Dnn.JQuery.JQuery), "jquery-1.3.2", VirtualPathUtility.ToAbsolute("~/DesktopModules/Succell.JQuery/js/jquery-1.3.2.js"));
        //            Dnn.JQuery.JQuery.RegisterJQuery(base.Page);
        //            base.Page.ClientScript.RegisterClientScriptInclude(typeof(JQueryUI), "jquery-ui-1.7.2",
        //                                                               VirtualPathUtility.ToAbsolute(
        //                                                                   "~/DesktopModules/Succell.JQuery/js/jquery-ui-1.7.2.js"));
        //        }

        //        return base.Page;
        //    }
        //    set
        //    {
        //        base.Page = value;
        //    }
        //}

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!String.IsNullOrEmpty(this.txtThemeName.Text))
            {
                try
                {
                    JQueryUI.RegisterJQueryUITheme(this.Page, this.txtThemeName.Text);
                    JQueryUI.SetDefaultJQueryUITheme(this.Page, this.txtThemeName.Text);
                    this.lblThemeName.Text = "Theme: ";
                }
                catch (Exception)
                {
                    this.lblThemeName.Text = "<span style=\"color: red\">Theme does not exist.</span> Theme: ";
                }
            }

            if (this.ModuleConfiguration.IsPremium)
            {
                this.lblPremiumMessage.Visible = false;
            }
            this.sliderNormalTest.ClientEvents.Slide =
                String.Format(CultureInfo.InvariantCulture,
                              "jQuery('{0}').html(ui.value);if (!{1}) {2}",
                              Dnn.JQuery.JQuery.JQueryClientID(this.lblSliderValue),
                              this.dlgSliderValue.ClientMethods.IsOpen(),
                              this.dlgSliderValue.ClientMethods.Open());

            if (this.IsPostBack)
            {
                this.lblSliderNormalTestValue.Text = String.Format(CultureInfo.CurrentCulture, this.lblSliderNormalTestValue.Text, this.sliderNormalTest.Value);
                this.lblSliderNormalTestValue.Visible = true;
                this.lblSliderRangeTestValue.Text = String.Format(CultureInfo.CurrentCulture, this.lblSliderRangeTestValue.Text, this.sliderRangeTest.LowValue, this.sliderRangeTest.HighValue);
                this.lblSliderRangeTestValue.Visible = true;
            }
            this.btnStartProgress.OnClientClick = "startProgress(); return false;";
        }
    }
}
